<template>
  <view class="verification">
    <view class="verification-top">
      <text>输入消费券券号核销</text>
      <image :src="scanicon" @tap="getScanCode"></image>
      <input type="text" v-model="qrcodetext" />
      <view class="btn">
        <button @tap="onVerification">确认核销</button>
      </view>
    </view>

    <view class="writeoff">
      <view class="writeoff-title">近期核销流水</view>
      <writeoff-list :data="list"></writeoff-list>
    </view>
  </view>
</template>

<script>
import "./index.scss";
import Vue from "vue";
import Taro from "@tarojs/taro";
import scan from "../../../assets/icon/scan.png";
import personicon from "../../../assets/icon/personicon.png";
import writeoffList from "../components/writeoffList/index";
import requset from "../../../utils/request";

export default {
  components: {
    "writeoff-list": writeoffList,
  },
  data() {
    return {
      qrcodetext: "",
      scanicon: scan,
      list: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      requset("get", "/api/rest/business_coupons.htm").then((res) => {
        this.list = res._list;
      });
    },
    getScanCode() {
      wx.scanCode({
        success: (res) => {
          this.qrcodetext = res.result;
        },
      });
    },

    onVerification() {
      requset("get", "/api/rest/business_coupon_use.htm", {
        coupon_number: this.qrcodetext,
      });
    },
  },
};
</script>
